function [sres] = pbm_bifsum(k)
% summmarize bifuraction analysis data...
% 12/3/98 P. Manis
%
if(nargin > 0)
   sf = k;
end

CONTROL = getuserdata;
if(isempty(CONTROL))
   QueMessage('Control is empty! ');
   return;
end

if(nargin == 0)
	list = find([CONTROL.pnd] == 1); % select the select group...
else
   list = k; % select just the input argument (list possible)
end
for sf=list
   newpath = drive_subst(CONTROL(sf).path); % get the correct path
   truefile = strcat(newpath, CONTROL(sf).filename); % make a filename
   [path name ext ver] = fileparts(truefile); % take filename apart for convenience
   [DFILE, data, err] = datac2mat(truefile, []); % just read the header - empty RL list
   if(err == 0) 
      QueMessage(sprintf('Processing: %s', name), 1);  % now we can do processing of the data
      mode = DFILE.dmode; % get the mode ... could also get it from CONTROL(sf).mode
      RL=number_arg(CONTROL(sf).recbeg):number_arg(CONTROL(sf).recend); % build record list (steps = 1)
      [DFILE, CURRENT, VOLTAGE, err] = readdatac_window(truefile, RL, CONTROL, sf, mode); % read, correct, and display the data
      QueMessage('Spec analysis'); % clear the que
      sres(sf) = speccalc(DFILE, VOLTAGE, 110,209,2, CONTROL(sf).thresh); % pass threshold to speccalc.....
      %       CONTROL=modctl; % update results from analysis
      if(length(list)==1)
         u = size(VOLTAGE);
         onetrace(DFILE, CURRENT, VOLTAGE, u(1));
      end
      
   else % an error occurred when attempting to read the file
      switch err
      case 1
         QueMessage(sprintf('Unable to open file? %s', truefile));
      case 2
         QueMessage('% is an empty file', name);
      otherwise
      end
   end
end

function onetrace(dfile, current, voltage, n)
% plot one trace in a separate figure, no current
time = make_time(dfile);
figurename = sprintf('%s - R: %d', dfile.filename, n);
h2 = findobj('Tag', figurename); % check for pre-existing window
if(isempty(h2)) % if none, make one
   h2 = figure('Tag', figurename, 'Name', 'OneTrace(pbm_bifsum)', 'NumberTitle', 'off');
end
figure(h2); % otherwise, select it
clf; % always clear the window...
vtag = sprintf('A%d', n);
b = mean(mean(voltage(n,1:5)));
wid = 0.5; ht = 0.4;
linestyle =1;
physplot(h2, vtag, time, voltage(n,:), [0.25, 0.25, wid, ht], ...
   [0, 350, -120, 40], b, [235, 20, -60, 20], 'ms', 'mV', linestyle);
return;


